package com.excilys.controller;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.excilys.model.Logbar;
import com.excilys.model.User;
import com.excilys.service.UserService;
import com.excilys.utils.UserUtils;

/**
 * Class that takes care of the user's accounts page
 * 
 * @author excilys dev : GF
 * 
 */
@Controller
@RequestMapping("/accounts")
public class AccountsController {

	org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AccountsController.class);

	/**
	 * Displays the actual user's custom page / http request : GET / jsp
	 * response : accounts.jsp
	 * 
	 */

	@Autowired
	private UserService userService;

	@RequestMapping(method = RequestMethod.GET)
	public void displayAccountsList(Model model) {
		(new Logbar()).setContent(model);
		DateTime currentDate = new DateTime();
		model.addAttribute("currentDate", currentDate);
		User currentUser = UserUtils.getConnectedUser();
		User user = userService.getUserByLogin(currentUser.getUserLogin());
		model.addAttribute("accountList", user.getUserListAccounts());
	}
}
